home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 076-100 / disk_084 / ed / omatch.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  1KB  |  65 lines

  1. #include <stdio.h>
  2. #include "tools.h"
  3.  
  4. /*
  5.  * Match one pattern element, pointed at by pat, with the character at
  6.  * **linp.  Return non-zero on match.  Otherwise, return 0.  *Linp is
  7.  * advanced to skip over the matched character; it is not advanced on
  8.  * failure.  The amount of advance is 0 for patterns that match null
  9.  * strings, 1 otherwise.  "boln" should point at the position that will
  10.  * match a BOL token.
  11.  */
  12. omatch(linp, pat, boln)
  13. char    **linp;
  14. TOKEN    *pat;
  15. char    *boln;
  16. {
  17.     
  18.     register int    advance;
  19.  
  20.     advance = -1;
  21.  
  22.     if (**linp)
  23.     {
  24.         switch (pat->tok)
  25.         {
  26.         case LITCHAR:
  27.             if (**linp == pat->lchar)
  28.                 advance = 1;
  29.             break;
  30.  
  31.         case BOL:
  32.             if (*linp = boln)
  33.                 advance = 0;
  34.             break;
  35.  
  36.         case ANY:
  37.             if (**linp != '\n')
  38.                 advance = 1;
  39.             break;
  40.  
  41.         case EOL:
  42.             if (**linp == '\n')
  43.                 advance = 0;
  44.             break;
  45.  
  46.         case CCL:
  47.             if( testbit( **linp, pat->bitmap))
  48.                 advance = 1;
  49.             break;
  50.  
  51.         case NCCL:
  52.             if (!testbit (**linp, pat->bitmap))
  53.                 advance = 1;
  54.             break;
  55.  
  56.         default:
  57.             printf("omatch: can't happen\n");
  58.         }
  59.     }
  60.     if (advance >= 0)
  61.         *linp += advance;
  62.  
  63.     return (++advance);
  64. }
  65.